<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let a = 10;
        console.log(typeof a); // number 数字. 不区分整数和小数.

        let b = "hello";
        console.log(typeof b); // string

        let c;
        console.log(typeof c); // undefined

        let d = true;
        console.log(typeof d); // boolean

        console.log("5/2 = " + (5 / 2));

        let e = "10";
        console.log("a == e: " + (a == e)); // true ==比较值（会进⾏隐式类型转换）
        console.log("a === e: " + (a === e)); // false ===比较值和类型（不会进⾏隐式类型转换）

        // 数组
        let arr = new Array();
        let arr2 = [];
        let arr3 = [1, 2, "e", "apple", true];
        console.log(typeof arr3);
        console.log(arr3);

        // 增
        arr2[0] = "aa";
        arr2[1] = "bb";
        arr2[5] = "cc";
        arr2["hello"] = "array";
        arr2[-3] = "-3";
        console.log(arr2);
        // 改
        arr2[5] = "ee";
        console.log(arr2);
        // 查
        console.log(arr3[3]);
        // 删
        arr3.splice(2, 3);
        console.log(arr3);

        // 函数定义
        function hello() {
            console.log("hello!");
        }
        // 函数调用
        hello();

        function add(x, y) {
            let sum = x + y;
            console.log(x + "+" + y + "=" + sum);
            return sum;
        }
        add(3, 5);
        add("aa", 3);
        add("aa", "bb");
        add("aa");
        add("aa", "bb", "cc");
        add(5); // 5+undefined=NaN  NaN：not a number

        // 接收返回值
        let ret = add(10, 20);
        console.log(ret);

        // 匿名函数
        let sum = function (x, y) {
            return x + y;
        }
        console.log(typeof sum); // function
        console.log(sum(1, 2)); // 3

        // 1. 使用 字面量{} 创建对象
        let obj = {};
        // 给属性赋值
        obj.name = "zhangsan";
        obj.age = 15;
        obj['gender'] = "男";
        console.log(obj);
        // 修改属性
        obj.age = 17;
        obj['name'] = "lisi";
        console.log(obj);

        // 字符串可以使用单引号，也可以使用双引号
        // key 的引号可以省略，value 的引号不能省略
        let stu = {
            "id": 5,
            "name": "wangwu",
            "age": 18
        };
        console.log(typeof stu);
        stu['gender'] = "女";
        stu.gender = "男";
        console.log(stu);

        // 2. 使⽤ new Object 创建对象
        let obj2 = new Object();
        console.log(typeof obj2);

        // 3. 使⽤ 构造函数 创建对象
        function Cat(name, age, color) {
            this.name = name;
            this.age = age;
            this.color = color;
        }
        let mimi = new Cat("mimi", 1, "yellow");
        console.log(mimi);

    </script>
</body>

</html>